from Students import Stu #从Students模块中导入Stu类

students = Stu()   #实例化Stu类对象students

def show():
    '''输出查询到的学生信息'''
    a = students.findAll()    #调用Stu类中findAll方法，实现数据查询，并返回查询结果
    if len(a)==0:
        print("=========没有学员信息============")
        return
    print("|{0:<5}| {1:<10}| {2:<5}|{3:<10}|".format("sid","name","age","class"))
    print("-"*40) 
    for i in range(len(a)):
              print("|{0:<5}| {1:<10}| {2:<5}|{3:<10}|".format(a[i][0],a[i][1],a[i][2],a[i][3]))   #输出查询结果

while True:
    #输出初始界面
    print("="*12,"学员管理系统","="*14)
    print("{0:1}{1:13}{2:15}".format(" ","1. 查看学员信息","2. 添加学员信息"))
    print("{0:1}{1:13}{2:15}".format(" ","3. 删除学员信息","4. 退出系统"))
    print("="*40)
    key=input("请输入对应的选择:")
    #根据键盘值，判断并执行对应的操作
    #信息查询
    if key == "1":
        print("="*12,"学员信息浏览","="*14)
        show()    
        input("按回车键继续")
    #添加学员信息
    elif key == "2":
        print("="*12,"学员信息添加","="*14)
        sid = int(input("请输入要添加的编号："))
        name = input("请输入要添加的姓名：")
        age = int(input("请输入要添加的年龄："))
        classid = input("请输入要添加的班级：")
        data = (sid,name,age,classid)
        students.insert(data)
        show()
        input("按回车键继续")
    #删除学员信息
    elif key=="3":
        print("="*12,"学员信息删除","="*14)
        show()
        id = int(input("请输入要删除的id号:"))
        students.dele(id)
        show()
        input("按回车键继续")
    #退出查询
    elif key=="4":
        print("="*12,"再见","="*14)
        break
    else:
        print("="*12,"无效的键盘输入","="*14)

